<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资方放款对账 列表</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
			<div class="FXBR">
				<div class="fieldBox ">
					<div class="label">文件日期</div>
					<div class="field">
						<input name="fileDateStart" id="fileDateStart" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
						----
						<input name="fileDateEnd" id="fileDateEnd" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
					</div>
				</div>
				<div class="fieldBox">
					<div class="label">资方</div>
					<div class="field">
						<select name="loanChannel" id="loanChannel">
							<option value="" seleted>请选择</option>
							<option value="YNXT">云信</option>
							<option value="WKXT">五矿</option>
						</select>
					</div>
				</div>
				<div class="fieldBox">
					<div class="label">对账类型</div>
					<div class="field">
						<select name="checkType" id="checkType">
							<option value="" seleted>请选择</option>
							<option value="1">放款</option>
							<option value="2">回款</option>
							<option value="3">回购</option>
							<option value="4">逾期</option>
						</select>
					</div>
				</div>
			</div>

			<div class="FXBR">
				<div class="fieldBox ">
					<div class="label">对账完成时间</div>
					<div class="field">
						<input name="checkTimeStart" id="checkTimeStart" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
						----
						<input name="checkTimeEnd" id="checkTimeEnd" type="text" class="ui-datepicker" ligerui="width: 115" required="required" readonly="readonly">
					</div>
				</div>
				<div class="fieldBox">
					<div class="label">是否存在差异</div>
					<div class="field">
						<select name="diffStatus" id="diffStatus">
							<option value="" seleted>请选择</option>
							<option value="1">是</option>
							<option value="2">否</option>
						</select>
					</div>
				</div>
				<div class="fieldBox">
					<div class="label">对账状态</div>
					<div class="field">
						<select name="fileStatus" id="fileStatus">
							<option value="" seleted>请选择</option>
							<option value="unProcessed">未开始</option>
							<option value="processing">处理中</option>
							<option value="finished">已完成</option>
						</select>
					</div>
				</div>
			</div>

            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	                <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
	                <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
	                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="mcrBillCheckGrid" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		// initDatePicker();

		// 日期控件初始化显示
		$('#fileDateStart,#fileDateEnd,#checkTimeStart,#checkTimeEnd').val(currentDate());
	});

	// 日期控件
	function initDatePicker() {

		// ==== 对账日期控件 =====

		//设置开始时间
		$("#fileDateStart").datepicker().on('changeDate', function(e) {
			//获取选取的开始时间
			var endTimeStart =$("#fileDateStart").val();
			//设置结束时间
			$('#fileDateEnd').datepicker('setStartDate', endTimeStart);
		});
		//设置结束时间必须晚于开始时间
		$("#fileDateEnd").datepicker().on('changeDate', function(e) {
			//获取选取的开始时间
			var endTimeStart =$("#fileDateStart").val();
			//设置结束时间
			$('#fileDateEnd').datepicker('setStartDate', endTimeStart);
		});
	}

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}

	// 当前日期格式化展示
	function currentDate() {
		return DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD);
	}

	//查询按钮事件
	function searchBtn(){
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#mcrBillCheckGrid").ligerGrid({
	    	url: '<%=path%>/mcr/mcrBillCheck/initList.do',
	    	method : 'post',
	    	isSingleCheck: false,
	    	parms:getSearchParams(),
	        columns: [
	            { display: '文件日期', name: 'fileDate', width: 100, enabledSort:true },
	            { display: '资方', name: 'loanChannel', width: 100, enabledSort:true},
	            { display: '对账类型', name: 'checkType', width: 100, enabledSort:true,
                    render: function (rowData) {
                        if (rowData.checkType == 1) {
                            return "放款";
                        } else if (rowData.checkType == 2) {
                            return "还款对账";
                        } else if (rowData.checkType == 3) {
                            return "回购对账";
                        } else if (rowData.checkType == 4) {
                            return "逾期对账";
                        } else {
                            return "未知";
                        }
                    }
				},
                { display: '狮桥总金额(元)', name: 'shiqiaoAmt', width: 150, enabledSort:true,},
				{ display: '资方总金额(元)', name: 'loanAmt', width: 150, enabledSort:true},
				{ display: '狮桥总笔数', name: 'shiqiaoAmount', width: 100, enabledSort:true},
				{ display: '资方总笔数', name: 'loanAmount', width: 100,enabledSort:true},
				{ display: '是否存在差异', name: 'diffStatus', width: 100, enabledSort:true,
					render:function(rowData){if(rowData.diffStatus==1){return "是";}else{return "否";}}
				},
				{ display: '差异笔数', name: 'diffAmount', width: 100, enabledSort:true,},
				{ display: '差异金额(元)', name: 'diffAmt', width: 150, enabledSort:true,},
				{ display: '对账状态', name: 'fileStatus', width: 100, enabledSort:true,
					render:function(rowData){
					if(rowData.fileStatus=="writing"){
						return "正在拉取";
					}else if (rowData.fileStatus=="unProcessed"){
						return "对账未处理";
					}else if (rowData.fileStatus=="processing"){
						return "对账处理中";
					}else if (rowData.fileStatus=="finished"){
						return "对账已完成";
					}
				}
				},
	            getGridOperColumnContent(),
				{ display: '对账完成时间', name: 'checkTime', width: 150, render:renderDate, enabledSort:true,}
			],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("mcrBillCheckGrid");
	    grid.setHeight(100);
	}

  	//Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
				render: function (rowdata, rowindex, value) {
					var h1 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="exportFile(' + rowdata.id + ',\'diffFile\')"><i class="sqBtnIco_4"></i>差异文件</a>'
					var h2 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="exportFile(' + rowdata.id + ',\'loanFile\')"><i class="sqBtnIco_13"></i>资方文件</a>';
                    if(rowdata.checkType !="1"){
                        var h3 = '<a class="sq-button-hasicon" href="javascript:void(0);" onclick="openCheckInfo(' + rowdata.id + ')"><i class="sqBtnIco_13"></i>对账详情</a>';
                        return h3;
                    }else{
                        return h1 + h2;
                    }
				}
            }
    	return data;
	}

	// 导出文件
	<%--function outExcel(id, type) {--%>
	<%--	var stsstr = "确认导出";--%>
	<%--	$.ligerDialog.confirm(stsstr, function (flag) {--%>
	<%--		if (flag == false) return;--%>
	<%--		var wait_dialog;--%>
	<%--		$.ajax({--%>
	<%--			type: 'post',--%>
	<%--			dataType: 'json',--%>
	<%--			data: {--%>
	<%--				outExcelId: JSON.stringify(id),--%>
	<%--				outExcelType: JSON.stringify(type)--%>
	<%--			},--%>
	<%--			url: '<%=path%>/mcr/mcrBillCheck/billCheckExport.do',--%>
	<%--			beforeSend:function(){--%>
	<%--				wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});--%>
	<%--			},--%>
	<%--			success: function (msg) {--%>
	<%--				wait_dialog.close();--%>
	<%--				if (msg.success == 1) {--%>
	<%--					$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});--%>
	<%--					grid.reload();--%>
	<%--				} else {--%>
	<%--					$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});--%>
	<%--				}--%>
	<%--			}--%>
	<%--		});--%>
	<%--	});--%>
	<%--}--%>

	function exportFile(id, type) {
		var req = "checkId="+id+"&outExcelType="+type;
		window.location.href="<%=path%>/mcr/mcrBillCheck/billCheckExport.do?"+req;
	}
	//对账详情页
	function openCheckInfo(_id){
		$.ligerDialog.SQopen({
			width: 800,
			height:400,
			title : '核对详情',
			url:'<%=path%>/mcr/mcrBillCheck/toCheckDetail.do?id='+_id,
			// 自定义buttons的时候 不要设置 fixButtons: true
			buttons: [{
				text: "更新", type: 'ok', cls: 'l-dialog-btn-ok',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onOk = function () {}
					if (Dialog.onOk) {
						Dialog.onOk();
					}
				}
			}, {
				text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
				onclick: function (item, Dialog) {
					//在子页面里绑定 frameElement.dialog.onCancel = function () {}
					if (Dialog.onCancel) Dialog.onCancel();
				}
			}
			]
		});
	}


	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "orgType":"",
		    "isValid":""
		  });
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
	
	//修改
	function update(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			UIUtils.alertError("请选择一条数据");
			return;
		}
		
		var _id = selectedRows[0].id;
		Add_navTab('Comp_2','修改','<%=path%>/mcr/mcrCityOpen/toAddPage.do?id='+_id);
		
		<%-- $.ligerDialog.SQopen({
            width: 800,
            height:200,
            title : '修改',
            url:'<%=path%>/mcr/mcrCityOpen/toAddPage.do?id='+_id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) {
	                    	Dialog.onOk();
	                    }
	                }
            		}, {
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        }); --%>
	}
	
</script>

</body>
</html>